package utils

import (
	"math"
	"strconv"
	"time"
)

func GetTomorrowTimeStamp()int64{
	now := time.Now()
	year:=now.Format("2006")        //年
	month := now.Format("01")     //月
	day:=now.Day()+1         //日
	tm2, _ := time.Parse("01/02/2006", month+"/"+strconv.Itoa(day)+"/"+year)
	//这个算的是 距离凌晨还有多久
	dayLongTime:=tm2.Unix()-(3600*8)-now.Unix()
	return dayLongTime
}

func TimeFormat(thisTime time.Time)string{
	return thisTime.Format("2006-01-02 15:04:05")
}

func ParseDate(thisTime time.Time)string{
	return thisTime.Format("2006-01-02")
}

func DateFormat(thisTime time.Time)string{
	var timeStr string
	now := time.Now()
	nowYear := now.Year()
	year := thisTime.Year()
	nowTimeStamp := now.Unix()
	timeStamp := thisTime.Unix()
	minus := nowTimeStamp - timeStamp
	if minus <= 60{
		timeStr = "刚刚"
	}else if minus > 60 && minus <= 60*60{
		myFloat := float64(minus) / 60
		roundValue := strconv.FormatInt(round(myFloat), 10)
		timeStr = roundValue + "分钟前"
	}else if 60 * 60 < minus && minus <= 60 * 60 * 24{
		myFloat := float64(minus) / (60 * 60)
		roundValue := strconv.FormatInt(round(myFloat), 10)
		timeStr = roundValue + "小时前"
	}else if 60 * 60 * 24 < minus && minus <= 60 * 60 * 24 * 30{
		myFloat := float64(minus) / (60 * 60 * 24)
		roundValue := strconv.FormatInt(round(myFloat), 10)
		timeStr = roundValue + "天前"
	}else if minus > 60 * 60 *24 * 30 && nowYear != year{
		myFloat := float64(minus) / (60 * 60 * 24 * 30)
		roundValue := strconv.FormatInt(round(myFloat), 10)
		timeStr = roundValue + "月前"
	}else{
		timeStr = thisTime.Format("2006-01-02")
	}
	return timeStr
}

func round(x float64)int64{
	return int64(math.Floor(x + 0/5))
}